package cn.mesmile.thread.jvm;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author zb
 * @date 2021/4/5 13:01
 * @Description:
 */
public class ObjectSize {


    public static void main(String[] args) {
        ClassLayout classLayout = ClassLayout.parseInstance(new Object());
        System.out.println("classLayout.toPrintable() = " + classLayout.toPrintable());

        System.out.println();
        ClassLayout classLayout2 = ClassLayout.parseInstance(new int[]{});
        System.out.println("classLayout2.toPrintable() = " + classLayout2.toPrintable());

        // 启用指针压缩:
        // XX:+UseCompressedOops(默认开启)，
        // 禁止指针压缩:
        // XX:-UseCompressedOops
        System.out.println();
        ClassLayout classLayout3 = ClassLayout.parseInstance(new Test());
        System.out.println("classLayout3.toPrintable() = " + classLayout3.toPrintable());
    }


    public static class Test{
        String username = "test";

        int a = 1;

        byte b = 1;   // 默认开启指针压缩，占用 4个字节，关闭指针压缩占用 8个字节

        Object object;
    }

}
